package com.hj.swagger;

import cn.hutool.core.util.RandomUtil;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * @author hj
 * @Date 2023/4/26
 * @Description: swagger配置文件
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
        return openApi -> {
            if (openApi.getTags()!=null){
                openApi.getTags().forEach(tag -> {
                    Map<String,Object> map=new HashMap<>(16);
                    map.put("x-order", RandomUtil.randomInt(0,100));
                    tag.setExtensions(map);
                });
            }
            if(openApi.getPaths()!=null){
                openApi.addExtension("x-hj","hj");
                openApi.getPaths().addExtension("x-hj",RandomUtil.randomInt(1,100));
            }

        };
    }

    @Bean
    public OpenAPI hjOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("hj-spring-cloud-3.0.6系统API")
                        .version("1.0")
                        .contact(new Contact().name("hj").url("www.baidu.com").email("hj@zhs.com"))
                        .description( "hj-API")
                        .termsOfService("www.hj.com")
                        .license(new License().name("Apache 2.0")
                                .url("www.hj.com")));
    }


}